package com.lwq.util;

import com.lwq.model.Dto;
import com.lwq.model.HashDto;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 * Description:
 * Author: LiuWenQing
 * Datetime: 2021/6/10
 */
public class IMSCxt {

    private static String excludeColumn = "pageNum,pageSize,orderByColumn,isAsc";

    public static Dto getParamAsDto(HttpServletRequest request){
        Dto dto = new HashDto();
        Map<String,String[]> map = request.getParameterMap();
        for(String key : map.keySet()){
            String value = "";
            /**
             * 适配mybatis-plus
             */
            if(Arrays.asList(excludeColumn.split(",")).contains(key)){
                continue;
            }
            if(map.get(key).length<=1){
                value=map.get(key)[0];
            }else{
                value= StringUtils.join(map.get(key),",");
            }
            dto.put(key,value);
        }
        return dto;
    }
}
